//泛型函数
function getData<T>(value:T):T{
    return value
}

console.log(getData<number>(123))

console.log(getData<string>('hello'))

function getMin<T>(arr:T[]):T{
    let minNum = arr[0];
    for(let i = 0;i<arr.length;i++){
        if(minNum > arr[i]){
            minNum = arr[i];
        }
    }
    return minNum
}

console.log(getMin<string>(['a','d','p']))
console.log(getMin<number>([11,4,6]))

//泛型类

class MinClass<T>{
    public list:T[]=[];
    add(num:T){
        this.list.push(num);
    }
    min():T{
        let minNum = this.list[0];
        for(let i = 0;i<this.list.length;i++){
            if(minNum > this.list[i]){
                minNum = this.list[i];
            }
        }

        return minNum
    }
}

let m = new MinClass<number>();

m.add(5);
m.add(100);
m.add(30);

console.log(m.min());

let str = new MinClass<string>();

str.add('o');

str.add('c');

str.add('b');

console.log(str.min())

//泛型接口
// interface FullDate{
//     (year:string,month:string):string
// }
// let getDate:FullDate = function(year:string,month:string):string{
//     return year+'-'+month
// }
interface Person1{
    name:string,
    age:number
}

interface Animal1{
    type:string
}

function create<T>(what:T):T{
    return what
}

console.log(create<Person1>({name:'lili',age:19}))

console.log(create<Animal1>({type:'cat'}))





